package ncku.account.gui.old;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;

import ncku.account.data.SubTransactionList;
import ncku.account.event.Launcher;
import ncku.account.gui.newTransaction;
import ncku.account.gui.subTransactionTable;

public class subTransactionFunction {
	//註解一下
    private JFrame frame;
    private subTransactionTable parentPanel;
	
	//新增一個dialog
    //public JDialog SubDialog;
    
    public subTransactionFunction(subTransactionTable input) {
    	//註解一下
    	this.parentPanel = input;  //將母panel儲存
    	
    	frame = new JFrame ("new subtransaction");
    	frame.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add (BorderLayout.CENTER,new Configuration());
        frame.pack();
        frame.setLocation(300, 150);
        frame.setSize(400,200);
        frame.setVisible (true);
    	
        //初始Dialog
    	//SubDialog = new JDialog();
    	//SubDialog.setTitle("新增交易明細");	
    	//SubDialog.setLayout(null);
    	//SubDialog.setSize(300, 200);
    	//SubDialog.setResizable(false);
    	//SubDialog.setLocation(400, 150);
    	//SubDialog.setVisible(true);	
    	//Configuration SubCon = new Configuration(description,amount);
        
    }
        
   class Configuration extends JPanel {
    	private JLabel JLdescription;
	    private JLabel JLamount;
	    private JButton JBSubmit;
	    private JButton JBCancel;
	    private JTextField inputDescriptionbox;
	    private JTextField inputAmountbox;
	    private String inputDescription;
	    private int inputAmount;
	    
    	public Configuration(){
    		//construct components
	    	JLdescription = new JLabel ("Description:");
	        JLamount = new JLabel ("Amount:");
	        JBSubmit = new JButton ("Submit");
	        JBCancel = new JButton ("Cancel");
	        inputDescriptionbox = new JTextField(10);
	        inputAmountbox = new JTextField(5);
	        
	        //adjust size and set layout
	        setPreferredSize (new Dimension (681, 422));
	        setLayout (null);
	        
	        //按下Submit後的Listener(new subTransaction)
	        JBSubmit.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) 
			{ 
		        inputDescription = inputDescriptionbox.getText();
		        inputAmount = Integer.parseInt(inputAmountbox.getText());
		//		newTransaction.subTransList.addSubTrans(inputDescription, inputAmount);
				
				
				
				Launcher.frame.getContentPane().remove(1);
				Launcher.frame.getContentPane().add (BorderLayout.CENTER,new newTransaction());
				Launcher.frame.getContentPane().doLayout();
				frame.dispose();
			}}); 
	        
	        //按下Cancel後的Listener(new subTransaction)
	        JBCancel.addActionListener(new ActionListener() { 
			public void actionPerformed(ActionEvent e) 
			{ 
				frame.dispose();
			}}); 
	        

	        //add components
	      //註解一下
	        add (JLdescription);
	        add (JLamount);
	        add (JBSubmit);
	        add (JBCancel);
	        add (inputDescriptionbox);
	        add (inputAmountbox);
	        //將元件加入Dialog 裡面
	        //SubDialog.add (JLdescription);
	        //SubDialog.add (JLamount);
	        //SubDialog.add (JBSubmit);
	        //SubDialog.add (JBCancel);
	       // SubDialog.add (inputDescriptionbox);
	        //SubDialog.add (inputAmountbox);
	       
	        //set component bounds (only needed by Absolute Positioning)	       
	        JLdescription.setBounds (25, 35, 100, 25);
	        JLamount.setBounds (45, 70, 100, 25);
	        JBSubmit.setBounds (65, 100, 80, 30);
	        JBCancel.setBounds (160, 100, 80, 30);
	        inputDescriptionbox.setBounds (100, 35, 150, 25);
	        inputAmountbox.setBounds (100, 70, 65, 25);	        
    	}
   }
}
